/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.hnilica.cisteniulic.dto;

import java.io.Serializable;
import java.util.Comparator;
import javassist.SerialVersionUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.commons.collections.comparators.NullComparator;

/**
 *
 * @author swosh
 */
@Entity
@Table(name = "ulice")
public class Ulice implements Serializable {
    private static final long serialVersionUID = 5222936611477340809L;
    private String nazUlice;
    private String nazCastiObce;
    private String nazObce;
    private static Comparator<String> nullSafeComparator = new NullComparator(String.CASE_INSENSITIVE_ORDER);

    public Ulice() {
    }

    public Ulice(String nazUlice) {
        this.nazUlice = nazUlice;
    }

    public Ulice(String nazUlice, String nazCastiObce, String nazObce ) {
        this.nazUlice = nazUlice;
        this.nazCastiObce = nazCastiObce;
        this.nazObce = nazObce;
    }

    @Id
    @Column(name="naz_ulice", nullable=false)
    public String getNazUlice() {
        return nazUlice;
    }

    public void setNazUlice(String nazUlice) {
        this.nazUlice = nazUlice;
    }
    @Column(name="naz_casti_obce", nullable=false)
    public String getNazCastiObce() {
        return nazCastiObce;
    }

    public void setNazCastiObce(String nazCastiObce) {
        this.nazCastiObce = nazCastiObce;
    }
    @Column(name="naz_obce", nullable=false)
    public String getNazObce() {
        return nazObce;
    }

    public void setNazObce(String nazObce) {
        this.nazObce = nazObce;
    }

     @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || (object.getClass() != this.getClass())) {
            return false;
        }
        Ulice ulice = (Ulice) object;
        int result = nullSafeComparator.compare(this.getNazUlice(), ulice.getNazUlice());
        if (result != 0) {
            return false;
        }
        result = nullSafeComparator.compare(this.getNazCastiObce(), ulice.getNazCastiObce());
        if (result != 0) {
            return false;
        }
        result = nullSafeComparator.compare(this.getNazObce(), ulice.getNazObce());
        if (result != 0) {
            return false;
        }
        return true;


    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (null == nazUlice ? 0 : nazUlice.hashCode());
        hash = 31 * hash + (null == nazCastiObce ? 0 : nazCastiObce.hashCode());
        hash = 31 * hash + (null == nazObce ? 0 : nazObce.hashCode());
        return hash;
    }

    public String toStringNotEndDot() {
        StringBuilder sB = new StringBuilder();
        if (nazUlice != null) {
            sB.append(nazUlice);
        } else {
            sB.append("null");
        }
        sB.append(", ");
        if (nazCastiObce != null) {
            sB.append(nazCastiObce);
        } else {
            sB.append("null");
        }
        sB.append(", ");
        if (nazObce != null) {
            sB.append(nazObce);
        } else {
            sB.append("null");
        }
        sB.append(" ");
        return sB.toString();
    }

}
